package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 用户详情服务接口实现
 */
@Service
public class UserInfoApiImpl implements UserInfoApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findById(Long id) {
        return userInfoMapper.selectById(id);
    }

    @Override
    public List<UserInfo> findByIdList(List<Long> userIdList, String gender, Long userId) {
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        wrapper.in("id", userIdList);
        wrapper.eq("gender", gender);
        wrapper.ne("id", userId);
        List<UserInfo> userInfoList = userInfoMapper.selectList(wrapper);
        return userInfoList;
    }

    @Override
    public IPage<UserInfo> findByPage(Integer page, Integer pagesize) {
        IPage<UserInfo> ipage = new Page<>(page, pagesize);
        IPage<UserInfo> result = userInfoMapper.selectPage(ipage, null);
        return result;
    }



    @Override
    public List<UserInfo> findByCharacter(int parseInt) {
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("character_id",parseInt);
        return userInfoMapper.selectList(wrapper);
    }


}
